<template>
  <div title="修改文章">
    <el-form :model="editForm"
             :rules="editFormRules"
             ref="editFormRef"
             label-width="100px">
      <el-form-item label="文章标题"
                    prop="title">
        <el-input v-model="editForm.title"
                  placeholder="请输入文章标题"></el-input>
      </el-form-item>
      <el-form-item label="文章内容"
                    prop="articleBody">
        <!-- 富文本编辑器组件 -->
        <quill-editor v-model="editForm.articleBody"></quill-editor>
      </el-form-item>
      <el-form-item label="视频地址"
                    prop="videoURL">
        <el-input v-model="editForm.videoURL"
                  placeholder="请输入视频地址"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button @click="$emit('close')">取消</el-button>
      <el-button type="primary"
                 @click="editArticle">确认</el-button>
    </span>
  </div>
</template>
<script>
import { update } from '@/api/hmmm/articles'
export default {
  name: 'ArticlesEdit',
  components: {},
  props: {
    editForm: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      editVisible: false,
      editFormRules: {
        title: [
          { required: true, message: '请输入文章标题', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        articleBody: [
          { required: true, message: '请输入文章内容', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }
        ],
        videoURL: [
          { required: true, message: '请输入视频地址', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  methods: {
    // 修改文章
    editArticle() {
      this.$refs.editFormRef.validate((valid) => {
        if (!valid) return

        update(this.editForm).then(() => {
          this.$message.success('修改文章成功')
          this.$emit('editAstr')
          // 关闭弹层
          this.$emit('close')
        })
      })
    }
  },
  created() {},
  mounted() {}
}
</script>
<style  scoped>
</style>
